package com.yuqian.JavaSe.java.sreflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class SProxy {
	public static void main(String[] args) {
		Human huanm = new Human();
		Eat run = (Eat) Proxy.newProxyInstance(Human.class.getClassLoader(), new Class[]{Run.class,Eat.class}, new ProxyHandler(huanm));
		//run.run();
		run.eat();
	}
}

interface Run{
	void run();
}

interface Eat{
	void eat();
}

class Human implements Run,Eat{

	public void run() {
		System.out.println("人类在奔跑");
	}

	public void eat() {
		System.out.println("人类在吃东西");
	}
}

class ProxyHandler implements InvocationHandler   
{   
  private Object proxied;   
     
  public ProxyHandler( Object proxied )   
  {   
    this.proxied = proxied;   
  }   
     
  public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable   
  {   
    //在转调具体目标对象之前，可以执行一些功能处理

	  System.out.println("准备奔跑");
	  
    //转调具体目标对象的方法
    method.invoke( proxied, args);  
    
    //在转调具体目标对象之后，可以执行一些功能处理
    System.out.println("奔跑ing");
    
    return null;
  }    
} 